package com.itheima.controller;

import com.itheima.common.Result;
import com.itheima.dto.MenuDTO;
import com.itheima.service.MenuService;
import com.itheima.vo.MenuVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单控制器
 *
 * @author 13225
 * @date 2023/09/21
 */
@RequestMapping("/sys_menu")
@RestController
@Slf4j
public class MenuController {
    private final MenuService menuService;

    public MenuController(MenuService menuService) {
        this.menuService = menuService;
    }

    /**
     * 所有数据
     *
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/allData")
    public Result<?> allData() {
        List<MenuVO> allMenu = menuService.allData();
        return Result.success(allMenu);
    }

    /**
     * del菜单
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/del")
    public Result<?> delMenu(String id) {
         menuService.delMenu(id);
        return Result.success();
    }

    /**
     * 行信息菜单
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/rowInfo")
    public Result<?> rowInfoMenu(String id) {
        MenuVO menuVO = menuService.rowInfoMenu(id);
        return Result.success(menuVO);
    }

    /**
     * 添加菜单
     *
     * @param menuDTO 菜单dto
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/add")
    public Result<?> addMenu(@RequestBody MenuDTO menuDTO){
        log.info("参数->"+menuDTO);
        menuService.addMenu(menuDTO);
        return Result.success();
    }

    /**
     * 更新菜单
     *
     * @param menuDTO 菜单dto
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/update")
    public Result<?> updateMenu(@RequestBody MenuDTO menuDTO) {
        log.info("参数->" + menuDTO);
        menuService.updateMenu(menuDTO);
        return Result.success();
    }
}
